import Mock from "mockjs";
// import nav from '../src/mock/home/nav.json' // 用json定义的nav数据

// 内存模拟数据 示例：
const arr = [];
for (let i = 0; i < 16; i++) {
  arr.push({
    id: Mock.mock("@id"),
    name: Mock.mock("@cname"),
    place: Mock.mock("@county(true)"),
  });
}

// 菜单栏数据
const navList = [
  { id: Mock.mock('@id'), label: '后台首页', router: '/', icon: 'User', children: [] },
  {
    id: Mock.mock('@id'), label: '后台管理', icon: 'Operation', children: [
      { id: Mock.mock('@id'), label: '用户管理', router: '/user', icon: '', children: [] },
      { id: Mock.mock('@id'), label: '岗位管理', router: '/post', icon: '', children: [] },
    ]
  },
  {
    id: Mock.mock('@id'), label: '系统工具', icon: 'Setting', children: [
      { id: Mock.mock('@id'), label: '通知公告', router: '/noticeAnnouncement', icon: '', children: [] },
      { id: Mock.mock('@id'), label: '日志管理', router: '/logManagement', icon: '', children: [] },
    ]
  },
  {
    id: Mock.mock('@id'), label: '其他业务', router: '/otherBusiness', icon: 'More', children: []
  },
]

export default [
  { // 获取菜单栏数据
    url: "/mock/navList",
    method: "get",
    response: () => {
      return {
        code: 200,
        message: "success",
        data: navList,
        // data: nav,
      };
    },
  },
  {
    url: "/del/:id",
    method: "delete",
    response: (req) => {
      const index = arr.findIndex((item) => item.id === req.query.id);
      if (index > -1) {
        arr.splice(index, 1);
        return { success: true };
      } else {
        return { success: false };
      }
    },
  },
  {
    url: "/edit/:id",
    method: "patch",
    response: ({ query, body }) => {
      const item = arr.find((item) => item.id === query.id);
      if (item) {
        item.name = body.name;
        item.place = body.place;
        return { success: true };
      } else {
        return { success: false };
      }
    },
  },
];
